package pl.prv.polanie.client.panels.lists;

import pl.prv.polanie.client.dialogs.CreateCalendarDayDialog;
import pl.prv.polanie.client.dto.CSCalendarDayDTO;
import pl.prv.polanie.client.dto.CSVCalendarDayDTO;
import pl.prv.polanie.client.model.Cache;
import pl.prv.polanie.client.model.ViewDataProvider;
import pl.prv.polanie.client.widgets.table.TableCalendarDays;

import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Widget;

public class CalendarDaysList extends ObjectsList {

	TableCalendarDays tableCalendarDays = new TableCalendarDays(this);

	public CalendarDaysList() {
		
		CSCalendarDayDTO[] ls = Cache.getAllCalendarDays();
		//AcademicTitleDTO[] ats = Cache.getAllAcademicTitles();
		
		add(tableCalendarDays);
		
		
		for (int i = 0; i < ls.length; i++) {
			
			CSCalendarDayDTO cs = ls[i];
			CSVCalendarDayDTO csv = ViewDataProvider.getCSVCalendarDay(cs);
			
			tableCalendarDays.addRow(cs, csv);
		}
		
		
		addRecordButton.addClickListener(new ClickListener(){
			public void onClick(Widget sender) {
				CreateCalendarDayDialog cld = new CreateCalendarDayDialog(CalendarDaysList.this, null); 
				cld.center();
				cld.setFocus();
			}
		});
		
		removeSelectedRecordButton.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				tableCalendarDays.removeSelectedCalendarDayFromTable();
			}
		});
		
		setupButtons();
	}

	
	public void addCSCalendarDay(CSCalendarDayDTO csCalendarDay) {
		tableCalendarDays.saveOrUpdateCalendarDayInTable(csCalendarDay);
	}
	
	public void removeSelectdCSCalendarDay() {
		tableCalendarDays.removeSelectedCalendarDayFromTable();
	}
	
}
